package com.mvc.app.implementations;

import com.container.app.MContainer;
import com.container.app.annotations.Component;
import com.mvc.app.Model;
import com.mvc.app.ModelGenerator;
import com.mvc.app.exceptions.IncompleteModelException;

import javax.servlet.http.HttpServletRequest;

import static com.mvc.app.utils.MVCUtils.getBeanInstances;

/**
 * Created with IntelliJ IDEA.
 * User: Georgiana.Scarlat
 * Date: 8/28/12
 * Time: 5:24 PM
 */

@Component
public class ModelGeneratorImpl implements ModelGenerator {

    public ModelGeneratorImpl() {
    }

    public Model createModel(MContainer container, HttpServletRequest request) {

        Model model = new Model();
        try {

            model.addBeans(getBeanInstances(container, request));

        } catch (IncompleteModelException e) {

            model.addBeans(e.getBeans());
            model.addProperties(e.getProperties());
        }

        return model;
    }


}
